//
//  EditCompanyInfoViewController.m
//  QXShowing
//
//  Created by 王道道 on 2018/5/17.
//  Copyright © 2018年 doll_dream. All rights reserved.
//

#import "EditCompanyInfoViewController.h"

@interface EditCompanyInfoViewController ()

@property (nonatomic, strong) UITextView *infoTV;
@property (nonatomic, strong) UIButton *rightButton;

@end

@implementation EditCompanyInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"公司介绍管理";
    self.view.backgroundColor = Bg_Color_F7F7F7;
    [self initNavBarBackBtn];
    [self setUpUI];
    [self initRightBtn];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setUpUI {
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = Bg_Color_FFFFFF;
    bgView.layer.masksToBounds = YES;
    bgView.layer.cornerRadius = 5;
    [self.view addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(15);
        make.top.equalTo(self.view.mas_top).offset(35);
        make.height.offset(160);
        make.centerX.equalTo(self.view);
    }];
    
    self.infoTV = [[UITextView alloc] init];
    self.infoTV.delegate = self;
    [bgView addSubview:self.infoTV];
    [self.infoTV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bgView.mas_left).offset(10);
        make.centerX.equalTo(bgView);
        make.top.equalTo(bgView.mas_top).offset(10);
        make.centerY.equalTo(bgView);
    }];
}

- (void)initRightBtn {
    _rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_rightButton setFrame:CGRectMake(0, 0, 60, 44)];
    //    [rightButton setImage:[UIImage imageNamed:@"my-2"] forState:UIControlStateNormal];
    [_rightButton setTitle:@"提交" forState:UIControlStateNormal];
    [_rightButton setTitleColor:Text_Color_000000 forState:UIControlStateNormal];
    [_rightButton setBackgroundColor:[UIColor clearColor]];
    [_rightButton addTarget:self action:@selector(editAction) forControlEvents:UIControlEventTouchUpInside];
    [_rightButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:_rightButton];
    self.navigationItem.rightBarButtonItem = rightItem;
}

- (void)editAction {
    if ([BHSettingUtil dataAndStringIsNull:self.infoTV.text]) {
        [[BHAlertUtil alertManager]showPromptInfo:@"请输入公司介绍"];
    } else {
        [self requestPostBH_User_editCompany];
    }
}
//编辑
- (void)requestPostBH_User_editCompany {
    [[BHAlertUtil alertManager]showLoading:nil];
    SGUserModel *userModel = [SGUserInfo getUserInfo];

    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    if (![BHSettingUtil dataAndStringIsNull:userModel.company_id]) {
        [params setObject:userModel.company_id forKey:@"company_id"];
    }
    [params setObject:self.infoTV.text forKey:@"description"];
    
//    [params setObject: forKey:@"contacts"];
//    [params setObject: forKey:@"phone"];
//    [params setObject: forKey:@"city_id"];
//    [params setObject: forKey:@"trade_id"];
//    [params setObject: forKey:@"logo"];
//    [params setObject: forKey:@"license"];

    [PPHTTPRequest requestPostBH_User_editCompany:^(id response, BOOL success) {
        [[BHAlertUtil alertManager]hiddenLoading];
        if (success) {
            [[BHAlertUtil alertManager] showPromptInfo:@"编辑成功"];
            [self.navigationController popViewControllerAnimated:YES];
        }
        else
        {
            
        }
    } params:params];
}

@end
